﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.OfficeArt
{
    internal class OfficeArtSplitMenuColorContainer : OfficeArtRecord
    {
        private readonly List<MSOCR> smca = new List<MSOCR>();

        public override RecType RecordType
        {
            get { return RecType.OfficeArtSplitMenuColorContainer; }
        }

        internal static OfficeArtSplitMenuColorContainer Default
        {
            get
            {
                OfficeArtSplitMenuColorContainer result = new OfficeArtSplitMenuColorContainer();
                result.smca.AddRange(GetDefaultColors);
                return result;
            }
        }
        static IEnumerable<MSOCR> GetDefaultColors
        {
            get
            {
                yield return MSOCR.FromRGBI (13, 0, 0, true);
yield return MSOCR.FromRGBI (12, 0, 0, true);
yield return MSOCR.FromRGBI(23, 0, 0, true);
yield return MSOCR.FromRGBI(247, 0, 0, false);

            }
        }

        protected override void ReadNoHeader(OfficeArtReadContext context)
        {
            Contract.Assert(rhrecVer == 0);
            Contract.Assert(rhrecInstance == 4);
            Contract.Assert(rhrecLen == 0x00000010);
            for (int i = 0; i < 4; i++)
            {
                var item = new MSOCR();
                item.Read(context.Reader);
                smca.Add(item);
            }
        }

        protected override byte Version
        {
            get { return 0; }
        }

        protected override int ByteLength
        {
            get { return 4*MSOCR.ByteLength; }
        }


        protected override void WriteNoHeader(OfficeArtWriteContext context)
        {
            Contract.Assert(rhrecVer == 0);
            Contract.Assert(rhrecInstance == 4);
            Contract.Assert(rhrecLen == 0x00000010);
            Contract.Assert(smca.Count == 4);
            foreach (MSOCR item in smca)
                item.Write(context.Writer);
        }

        protected override void PrepareHeader(ref OfficeArtRecordHeader rh)
        {
            rh.recVer = 0;
            rh.recInstance = 0x004;
            rh.recLen = 0x10;
        }
    }
}